/*
 * INSANE - Interactive Structural Analysis Environment
 *
 * Copyright (C) 2003-2006
 * Universidade Federal de Minas Gerais
 * Escola de Engenharia
 * Departamento de Engenharia de Estruturas
 *
 * Author's email :     insane@dees.ufmg.br
 * Author's Website :   http://www.dees.ufmg.br/insane
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
 * 1307, USA.
 * 
 */

package br.ufmg.dees.insane.util.extrapolation;

import java.util.ArrayList;

import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.INaturalCoords;

/** 
 * The class represents an extrapolation of values in two dimension.
 * @author Penna, Samuel & Pitangueira, Roque
 * @since novenber 2006
 */
public class LagrangeanExtrapolation2D extends LagrangeanExtrapolation{
	
    /**
     * The default's constructor.
     */
	public LagrangeanExtrapolation2D() {

    }
	
    /**
     * Initialize the lagrangean extrapolation to it values and it coords.
     */
	public LagrangeanExtrapolation2D(ArrayList natCoords,ArrayList values) {
        super(natCoords,values);
    }
	
	/** 
     * The method return the qsi and Eta terms matrix of lagrangean's polynomial 
     * respective to it natural coords.
     * @param p The natural coords.
     * @return fi The matrix with terms.
     */
    private IMatrix fiAux(INaturalCoords p){
    	IMatrix fiQsi = fiQsi(p);
    	IMatrix fiEta = fiEta(p);
        fiQsi.transpose();
        IMatrix fiAux = fiQsi;
        fiAux.mul(fiEta);
        return fiAux;
    }
	
    /** 
     * The method return the terms matrix of lagrangean's polynomial 
     * respective to it natural coords.
     * @param p The natural coords.
     * @return fi The matrix with the polynomial terms.
     */
    protected IMatrix fi(INaturalCoords p){
        int num = this.naturalCoords.size();
        int numCont = (int)Math.sqrt(this.naturalCoords.size());
    	IMatrix fi = new IMatrix(1,num);
    	IMatrix aux = fiAux(p);
        int cont = 0;
    	for (int i = 0; i < numCont; i++){
    		for (int j = 0; j < numCont; j++){
    			fi.setElement(0,cont,aux.getElement(j,i));
                cont++;
			}
		}
        return fi;
    }
    
//*****************************************************************************
}
